package com.example.userprovider.exception;

import org.example.api.R;
import org.example.exception.BizException;
import org.example.exception.ValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @author
 * @date 2021-4-19 13:23
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public R handlerException(Exception e, HttpServletRequest request) {
        String msg = "系统繁忙:" +e.getMessage();
        if(e instanceof BizException || e instanceof ValidException) {
            msg = e.getMessage();
        }
        return new R.Builder().buildCustomize(msg);
    }
}
